//
//  leftViewController.m
//  project-A (pianke)
//
//  Created by dllo on 16/1/25.
//  Copyright © 2016年 scott. All rights reserved.
//

#import "leftViewController.h"
#import "videoController.h"
#import "searchView.h"
#import "GonglueOfVC.h"
#import "AppDelegate.h"
#import "VCOfxiangce.h"
#import "imageOftouxiang.h"
#import "nameOftouxiang.h"
#import "titleOftouxiang.h"
#import <DKNightVersion.h>
#import "VCOfshoucang.h"

#import "VCOfhuancun.h"

@interface leftViewController ()<UITableViewDataSource,UITableViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>

@property (nonatomic,retain)UITableView *tableview;


@property (nonatomic,retain)imageOftouxiang *image;

@property (nonatomic,retain)nameOftouxiang *labelname;

@property (nonatomic,retain)titleOftouxiang *labeltitle;



@property (nonatomic,retain)UISwitch *sw;
@end

@implementation leftViewController


-(void)dealloc{
    [_sw release];
    [_image release];
    [_tableview release];
    [_labeltitle release];
    [_labelname release];
    [super dealloc];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    self.view.dk_backgroundColorPicker = DKColorWithColors([UIColor blackColor],  [UIColor colorWithRed:0.16 green:0.14 blue:0.13 alpha:1]);
    UIImageView *imageview = [[UIImageView alloc]initWithFrame:self.view.bounds];
//    imageview.image = [UIImage imageNamed:@"2016.jpeg"];
    [self.view addSubview:imageview];
    imageview.dk_imagePicker = DKImageWithImages([UIImage imageNamed:@"2015.jpg"], [UIImage imageNamed:@"2016.jpeg"]);
    
    self.view.frame = [UIScreen mainScreen].bounds;
    
    [self creattabview];
    
    [self creatSwitch];

   }

- (void)creatSwitch {
    self.sw = [[UISwitch alloc] initWithFrame:CGRectMake(self.tableview.bounds.size.width / 2,self.view.bounds.size.height - 50, 30, 30)];
   
    [self.view addSubview:self.sw];
    [_sw release];
    [self.sw addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
}


- (void)switchAction:(UISwitch *)sw{
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    
    
    if ([DKNightVersionManager currentThemeVersion] == DKThemeVersionNight) {
        [DKNightVersionManager dawnComing];
    } else {
        [DKNightVersionManager nightFalling];
    }
    
    
    // 保存状态 , 程序再次启动时的偏好设置
    [user setBool:sw.on forKey:@"ISNIGHT"];
    [user synchronize];
    
}

-(void)creattabview{
    self.tableview = [[UITableView alloc]init];
    self.tableview.frame = self.view.bounds;
    self.tableview.backgroundColor = [UIColor clearColor];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableview];
    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"pool1"];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 6;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool1"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.font = [UIFont systemFontOfSize:20.0f];
   
    //字体颜色
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.textColor = [UIColor whiteColor];
    
    if (indexPath.row == 0) {
        cell.textLabel.text = @"一手新鲜";
    }else if (indexPath.row == 1){
        cell.textLabel.text = @"我的相册";
    }else if (indexPath.row == 2){
        cell.textLabel.text = @"游戏搜索";
    }else if (indexPath.row == 3){
        cell.textLabel.text = @"旅游攻略";
    }else if (indexPath.row == 4){
        cell.textLabel.text = @"个人收藏";
    }else if (indexPath.row == 5){
        cell.textLabel.text = @"个性设置";
    }
    
    return cell;
}


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    
    return 250;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.tableview.bounds.size.width, 250)];
    
    
    self.image = [[imageOftouxiang alloc]initWithFrame:CGRectMake(0, 0, 70, 70)];
    self.image.center = CGPointMake(self.tableview.bounds.size.width * 1 / 4, 125);
    
    [view addSubview:self.image];
    
    self.image.backgroundColor = [UIColor whiteColor];
    
  self.image.layer.borderWidth = 1;
   self.image.layer.borderColor = [UIColor whiteColor].CGColor;
    self.image.layer.cornerRadius = 35;
    
    self.image.layer.masksToBounds = YES;
    
    self.image.special.image = [UIImage imageNamed:@"saber"];

    
    
    self.image.block  = ^(){
        
        NSLog(@"换头像");
        
        
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
        imagePicker.allowsEditing = YES;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.delegate = self;
        [self presentViewController:imagePicker animated:YES completion:^{
            NSLog(@"打开相册");
        }];

        
    };

    self.labelname = [[nameOftouxiang alloc]initWithFrame:CGRectMake(0, 0, 150, 30)];
    self.labelname.center = CGPointMake(self.tableview.bounds.size.width *2 / 3 , 125);
    [view addSubview:self.labelname];
    
    self.labelname.labelOfname.text= @"ゞ灬飝翔啲荷蘭亻亼╰→";
    self.labelname.block = ^(){
    
        
        NSLog(@"换名字");
    };
  
    self.labeltitle = [[titleOftouxiang alloc]initWithFrame:CGRectMake(0, 0, 150, 30)];
    self.labeltitle.center = CGPointMake(self.tableview.bounds.size.width / 3 ,180);
    [view addSubview:self.labeltitle];
    
    self.labeltitle.labelOftitle.text= @"The Flying Dutchman";
    self.labeltitle.block = ^(){
        
        NSLog(@"换签名");
    };

    
    
    
    return view;
    
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:^{
        NSLog(@"取消");
    }];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    self.image.special.image = info[UIImagePickerControllerEditedImage];
    NSLog(@"%@",info);
    [picker dismissViewControllerAnimated:YES completion:^{
        NSLog(@"选照片");
    }];
    
    
    
}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 1) {
        videoController *VC = [[videoController alloc]init];

        [self.tableview deselectRowAtIndexPath:indexPath animated:YES];
        AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
       
        [tempAppDelegate.LeftSlideVC closeLeftView];//关闭左侧抽屉
        
        [tempAppDelegate.mainNavigationController pushViewController:VC animated:NO];
        [VC release];
    }else if (indexPath.row == 2){
        
        searchView *vc = [[searchView alloc]init];
        
        [self.tableview deselectRowAtIndexPath:indexPath animated:YES];
        AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        
        [tempAppDelegate.LeftSlideVC closeLeftView];//关闭左侧抽屉
        
        [tempAppDelegate.mainNavigationController pushViewController:vc animated:NO];

        
        [vc release];
        
        
    }else if (indexPath.row == 3){
        
        GonglueOfVC *vc = [[GonglueOfVC alloc]init];
        
        
        [self.tableview deselectRowAtIndexPath:indexPath animated:YES];
        AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        
        [tempAppDelegate.LeftSlideVC closeLeftView];//关闭左侧抽屉
        
        [tempAppDelegate.mainNavigationController pushViewController:vc animated:NO];

        
        [vc release];
    }else if (indexPath.row == 0){
       
        
        
        [self.tableview deselectRowAtIndexPath:indexPath animated:YES];
        AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        
        [tempAppDelegate.LeftSlideVC closeLeftView];//关闭左侧抽屉
        
        
      

    }else if (indexPath.row == 4){
        VCOfshoucang *vc = [[VCOfshoucang alloc]init];
        
        
        [self.tableview deselectRowAtIndexPath:indexPath animated:YES];
        AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        
        [tempAppDelegate.LeftSlideVC closeLeftView];//关闭左侧抽屉
        
        [tempAppDelegate.mainNavigationController pushViewController:vc animated:NO];
        
        
//        [vc release];
    }else if (indexPath.row == 5){
        VCOfhuancun *vc = [[VCOfhuancun alloc]init];
        [self.tableview deselectRowAtIndexPath:indexPath animated:YES];
        AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        
        [tempAppDelegate.LeftSlideVC closeLeftView];//关闭左侧抽屉
        
        [tempAppDelegate.mainNavigationController pushViewController:vc animated:NO];
        [vc release];
        
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
